package cn.fscode.code.generator.common;

import cn.fscode.commons.core.response.Resp;
import cn.fscode.commons.core.response.context.RequestContext;
import cn.fscode.commons.core.response.filter.ResponseFormatFilter;
import cn.fscode.commons.core.response.format.IResponseFormatWrapper;
import cn.fscode.commons.core.response.format.model.ResponseFormat;
import cn.hutool.core.lang.func.LambdaUtil;
import org.springframework.stereotype.Component;

/**
 * cn.fscode.commons (project-commons工程下的自定义响应字段)
 * <a href="https://www.yuque.com/shenguangyang/rhoz1v/ouekmv">语雀文档</a>
 * @author shenguangyang
 */
@Component
public class CustomResponseFormat implements IResponseFormatWrapper, ResponseFormatFilter {
    @Override
    public ResponseFormat getWrapInfo() {
        return ResponseFormat.builder()
                .codeName(LambdaUtil.getFieldName(Resp<Object>::getCode))
                .dataName(LambdaUtil.getFieldName(Resp<Object>::getData))
                .successName(LambdaUtil.getFieldName(Resp<Object>::getSuccess))
                .messageName("message")
                .defaultFailCodeValue(-1)
                .successCodeValue(1)
                .build();
    }

    @Override
    public boolean isForceWrapDefault(RequestContext requestContext) {
        return false;
    }
}
